package com.zebra.gateway.session;

import io.netty.channel.Channel;
import io.netty.util.AttributeKey;

/**
 * @author Kui.Song
 * @date 2019/8/11 16:15
 */
public class ZebraAttribute {

  private ZebraAttribute() {
  }

  private static final AttributeKey<Session> SESSION = AttributeKey.newInstance("SESSION");
//  private static final AttributeKey<RegisterUrlVO> REGISTER = AttributeKey.newInstance("REGISTER");

  private static <T> T get(Channel channel, AttributeKey<T> key) {
    return channel.attr(key).get();
  }

  private static <T> void set(Channel channel, AttributeKey<T> key, T value) {
    channel.attr(key).set(value);
  }


  //-----------session-----------
  public static Session getSession(Channel channel){
    if (null == channel){
      return null;
    }

    return get(channel, SESSION);
  }

  public static <T> void setSession(Channel channel, Session session){
    if (null == channel || null == session){
      return;
    }
    set(channel, SESSION, session);
  }

  public static <T> void removeSession(Channel channel){
    if (null == channel){
      return;
    }
    set(channel, SESSION, null);
  }


  //-------------register------------
//  public static RegisterUrlVO getRegister(Channel channel){
//    if (null == channel){
//      return null;
//    }
//
//    return get(channel, REGISTER);
//  }
//
//  public static <T> void setRegister(Channel channel, RegisterUrlVO registerUrlVO){
//    if (null == channel || null == registerUrlVO){
//      return;
//    }
//    set(channel, REGISTER, registerUrlVO);
//  }


}